home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
os2
/
bingrab.zip
/
bingrab.cmd
next >
Wrap
OS/2 REXX Batch file
|
1997-08-08
|
14KB
|
443 lines
/*------------------------------------------------------------------
* REXX - OS/2 -- BINGRAB ver 0.1a
* bingrab.cmd : binaries grabber
* Grabs uudecoded files (multiple and single part) from newsgroups
* then decodes them into executable binaries.
* Requires rxsock.dll and uudeview.exe to function. I have included
* them, but STRONGLY URGE you to go get the complete file from
* FTP somewhere. They will have documentation on how to setup.
* The .rc files contain group info to track what groups to grab
* and also keep track of messages already downloaded.
* As to the multiple parts - It has it's limitations. You can adjust the
* minimum size of messages to download to a smaller value to maybe
* get the final part of a post, but you are also grabbing a bunch
* of time consuming garbage in the proccess. I have it set to 500.
* This is mainly because I don't want a bunch of small pictures in my
* directory or to spend time downloading files that are not pictures
* like .html files or text files. I have found that multiple part posts are
* missing pieces anyway. The few complete ones that get missed are
* probably not worth the extra coding it would take to go look for them.
* Also another important consideration is the number of group names
* in the binaries.grp file. For each group name listed, a seperate call to
* BINGRAB.CMD is called and a seperate server connection. This could
* lead to a slow machine or even errors. I recommend limiting it to less
* than 15, I have it set to 10. You can always create multiple .rc files
* that contain 10 - 15 names and run them at different times.
* I have included two utility programs. GROUPS.CMD will get a list of
* available BINARY groups from the server. This list then can be cut
* and pasted into the .rc files for BINGRAB.CMD. MOVE.CMD will move all
* jpg and gif files to a directory named the first characture of the file
* name. It will then delete any jpg or gif files left in the directory. This
* should eliminate any duplicate named files. At this time I have no way
* to determine if there are duplicate pictures with different names.
* My experience has been that there are to to many.
* I hope you like the program. It is EMAILware, so drop me a line if you
* use it and let me know how you like it and what enhancements you
* would like to see. I do not guarantee any further versions, but if any
* major bugs exist I will release an upgrade.
*
* Thanks, CyberLord. CyberLord@Cyber-Wizard.Com
*------------------------------------------------------------------*/
MINSIZE = 500 /*Minimum size of messages to download*/
MAXGROUPS = 10 /*Maximum number of server connections*/
parse upper source env how self .
parse arg arguments
address cmd
'@ECHO OFF'
call syscls
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say "BINGRAB v0.1a Newsgroup Binaries Grabber"
say "by Timothy Millea - CyberLord@Cyber-Wizard.com"
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if how = 'FUNCTION' then do
/* we were started as a function call... */
/* start us again as a separate session and return. */
say "Started as a function call"
say "calling ourselves"
'START' self arguments
say "Returning to program that called us"
return 0
end
parse arg server group new .
if new > 0 then do
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
call syscls
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
say "BINGRAB v0.1a Newsgroup Binaries Grabber"
say "by Timothy Millea - CyberLord@Cyber-Wizard.com"
say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if (server = "") then
do
say "Expecting a news server name to be passed as a parameter."
if (group = "") then
do
say "Expecting a newsgroup to be passed as a parameter."
exit 1
end
end
if (group = "") then
do
say "Expecting a newsgroup to be passed as a parameter."
exit 1
end
/*------------------------------------------------------------------
* initialize socket function package
*------------------------------------------------------------------*/
if RxFuncQuery("SockLoadFuncs") then
do
rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
rc = SockLoadFuncs()
end
/*------------------------------------------------------------------
* get address of server
*------------------------------------------------------------------*/
rc = SockGetHostByName(server,"host.!")
if (rc = 0) then
do
say "Unable to resolve server name" server
exit
end
server = host.!addr
/*------------------------------------------------------------------
* open socket
*------------------------------------------------------------------*/
sock = SockSocket("AF_INET","SOCK_STREAM",0)
if (sock = -1) then
do
say "Error opening socket:" errno
exit
end
/*------------------------------------------------------------------
* connect socket
*------------------------------------------------------------------*/
server.!family = "AF_INET"
server.!port = 119
server.!addr = server
rc = SockConnect(sock,"server.!")
if (rc = -1) then
Error(sock,rc,"Error connecting to newsserver :" errno)
trc = GetResponse(sock)
do i = 1 to line.0
say line.i
end
/**************************************************************
Catch breaks
***************************************************************/
signal on halt
rc = Interact(sock, group) /*Jump to interact function*/
/*------------------------------------------------------------------
* quittin' time!
*------------------------------------------------------------------*/
rc = SendMessage(sock,"quit")
rc = SockSoclose(sock)
uudeview.exe "+e .jpg.gif -i" group||".uue" /*decode file*/
rc = stream(group||".uue", 'c', 'close')
del group||".uue"
exit
/*------------------------------------------------------------------
* Get files from group loop
*------------------------------------------------------------------*/
Interact: procedure expose !.
sock = arg(1)
group = arg(2)
MINSIZE = 500 /*Minimum size of messages to download*/
trc = SendMessage(sock,"group" group)
trc = GetResponse(sock)
do i = 1 to line.0
say line.i
end /*do i*/
parse var line.1 code total begin end1 .
rccommand = linein(group||'.rc')
parse var rccommand rccode rctotal rcbegin rcend rcgroup
if group = rcgroup then do
begin = rcend
begin = begin + 1
end /*if*/
else if rcgroup != "" then do
say "Command line "GROUP" does not match with .rc file "RCGROUP
exit
end /*else if*/
say "Last message number read " rcend
say "Newest message number in group " end1
if begin > end1 then do
say "No new messages in " group
call lineout group||'.rc', code (rcend-rcend) rcend rcend group, 1
call lineout group||'.rc'
return ""
end
call lineout group||".uue", group,1
call lineout group||".uue","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
call lineout group||'.rc', code (begin-begin) begin begin group, 1
call lineout group||'.rc'
number = begin
parse value syscurpos() with row col
pos = syscurpos(row, col)
say "Getting header number " number " "
trc = SendMessage(sock, "head" number)
trc = GetResponse(sock)
do i = 1 to line.0
parse var line.i name lines .
if name = "Lines:" then leave
end /*if*/
if lines > MINSIZE then do
pos = syscurpos(row, col)
say "Getting message number " number " "
trc = SendMessage(sock, "article" number)
trc = GetResponse(sock)
say ""
say "Writing " line.0 "lines. "
do i = 1 to line.0
call lineout group||".uue",line.i
end /*do i*/
call lineout group||'.rc', code (number-begin) begin number group, 1 /*don't want to write number out until message*/
call lineout group||'.rc' /*is written to .uue file*/
end /*if*/
else do
call lineout group||'.rc', code (number-begin) begin number group, 1 /*write message number out to file*/
call lineout group||'.rc' /*after header is read even if less than MINSIZE lines*/
end /*else do*/
do forever
trc = SendMessage(sock, "next")
trc = GetResponse(sock)
parse var line.1 code number .
if code = 421 then do /*code 421 is an error that there are no more messages*/
say line.1
call lineout group||'.rc', code (rcend-rcend) rcend rcend group, 1
call lineout group||'.rc'
return ""
end /*if number*/
pos = syscurpos(row, col)
say "Getting header number " number " "
trc = SendMessage(sock, "head" number)
trc = GetResponse(sock)
do i = 1 to line.0
parse var line.i name lines .
if name = "Lines:" then leave
end /*if*/
if lines > MINSIZE then do
pos = syscurpos(row, col)
say "Getting message number " number " "
trc = SendMessage(sock, "article" number)
trc = GetResponse(sock)
say ""
say "Writing " line.0 "lines. "
do i = 1 to line.0
call lineout group||".uue",line.i
end /*do i*/
call lineout group||'.rc', code (number-begin) begin number group, 1 /*don't want to write number out until message*/
call lineout group||'.rc' /*is written to .uue file*/
end /*if*/
else do
call lineout group||'.rc', code (number-begin) begin number group, 1 /*write message number out to file*/
call lineout group||'.rc' /*after header is read even if less than MINSIZE lines*/
end /*else do*/
call lineout group||".uue","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
number = number + 1
if number > end1 then do
say "Finished processing newsgroup"
call lineout group||".uue"
leave
end /*if*/
end /*do forever*/
return ""
/*------------------------------------------------------------------
* send a string to the server
*------------------------------------------------------------------*/
SendMessage: procedure expose !.
sock = arg(1)
data = arg(2) || d2c(13) || d2c(10)
len = length(data)
do while (len > 0)
i = SockSend(sock,data);
if (errno <> 0) then
Error(-1,rc,"Error sending data to server.")
if (i <= 0) then
Error(sock,100,"Server closed the connection.")
data = substr(data,len+1)
len = length(data)
end
return 0
/*------------------------------------------------------------------
* get a response from the server
*------------------------------------------------------------------*/
GetResponse: procedure expose !. line.
sock = arg(1)
moreids = "100 215 220 221 222 223 230 231"
line.0 = 1
line.1 = GetResponseLine(sock)
parse var line.1 rid .
if (wordpos(rid,moreids) = 0) then
return ""
if rid = 223 then return ""
do forever
o = line.0 + 1
line.o = GetResponseLine(sock)
if (line.o = ".") then
return ""
line.0 = o
end
return ""
/*------------------------------------------------------------------
* get a line from the server
*------------------------------------------------------------------*/
GetResponseLine: procedure expose !.
sock = arg(1)
crlf = d2c(13) || d2c(10)
if (symbol('!.buff') = "LIT") then
!.buff = ""
do while (pos(crlf,!.buff) = 0)
rc = SockRecv(sock,"data",8000)
!.buff = !.buff || data
end
p = pos(crlf,!.buff)
line = substr(!.buff,1,p-1)
!.buff = substr(!.buff,p+2)
return line
/*------------------------------------------------------------------
* halting ...
*------------------------------------------------------------------*/
Halting:
Error(sock,1,"error on line" sigl)
/*------------------------------------------------------------------
* exit with a message and return code
*------------------------------------------------------------------*/
Error: procedure
sock = arg(1)
retc = arg(2)
msg = arg(3)
if (sock <> -1) then
rc = SockSoClose(sock)
say msg
exit retc
/*------------------------------------------------------------------
* close socket (and catch signals)
*------------------------------------------------------------------*/
halt:
rc = SendMessage(sock,"quit")
rc = SockSoClose(sock)
if (rc = -1) then
do
say "Error on SockSoClose:" errno
exit
end
uudeview.exe "+e .jpg.gif -i" group||".uue" /*decode file*/
rc = stream(group||".uue", 'c', 'close') /*close and delete .uue file*/
del group||".uue"
exit
end /*if new*/
else do
say lines(group)
number = 0
do while lines(group)
if number < MAXGROUPS then do
line = linein(group)
parse var line groupname .
rc = bingrab(server groupname 1)
number = number + 1
end /*if number*/
else do
say "Max number of groups reached"
exit
end /*else do*/
end /*do while lines*/
exit
end /*else do*/